package com.twu.biblioteca;

import com.twu.biblioteca.DataBase.ListOfItems;
import com.twu.biblioteca.Options.*;

import java.util.Scanner;

public class LibrarySystem {
    private final ListOfItems listOfItems;
    private final ListOptionsOption listOptionsOption;
    private Scanner scanner;
    private LoginOption loginOption;
    private LogoutOption logoutOption;
    private Account account;
    private DisplayUserInfoOption userInfoOption;

    public LibrarySystem() {
        listOfItems = new ListOfItems();
        listOptionsOption = new ListOptionsOption();
        account = new Account();
        loginOption = new LoginOption(account);
        logoutOption = new LogoutOption(account);
    }

    public void start() {
        scanner = new Scanner(System.in);
        Manager manager = new Manager();
        System.out.println("Welcome to Bangalore Public Library!");
        listOfItems.printBookList();
        while(account.getCurrentUser() == null){
            loginOption.execute();
            userInfoOption = new DisplayUserInfoOption(account.getCurrentUser());
        }

        while(account.getCurrentUser() != null){
            listOptionsOption.execute(listOfItems);
            System.out.println("Please choose the option!");
            String command = scanner.nextLine();
            if(command.equals(logoutOption.getName())){
                logoutOption.execute();
            }
            else if(command.equals(userInfoOption.getName())){
                userInfoOption.execute();
            }
            else {
                manager.handle(command);
            }
        }
    }
}
